using System;
using System.Collections;
using System.Collections.Generic;
namespace ICSharpCode.TextEditor.Document
{
	public sealed class SpanStack : ICloneable, IEnumerable<Span>, IEnumerable
	{
		internal sealed class StackNode
		{
			public readonly SpanStack.StackNode Previous;
			public readonly Span Data;
			public StackNode(SpanStack.StackNode previous, Span data)
			{
				this.Previous = previous;
				this.Data = data;
			}
		}
		public struct Enumerator : IEnumerator<Span>, IDisposable, IEnumerator
		{
			private SpanStack.StackNode c;
			public Span Current
			{
				get
				{
					return this.c.Data;
				}
			}
			object IEnumerator.Current
			{
				get
				{
					return this.c.Data;
				}
			}
			internal Enumerator(SpanStack.StackNode node)
			{
				this.c = node;
			}
			public void Dispose()
			{
				this.c = null;
			}
			public bool MoveNext()
			{
				this.c = this.c.Previous;
				return this.c != null;
			}
			public void Reset()
			{
				throw new NotSupportedException();
			}
		}
		private SpanStack.StackNode top;
		public bool IsEmpty
		{
			get
			{
				return this.top == null;
			}
		}
		public Span Pop()
		{
			Span data = this.top.Data;
			this.top = this.top.Previous;
			return data;
		}
		public Span Peek()
		{
			return this.top.Data;
		}
		public void Push(Span s)
		{
			this.top = new SpanStack.StackNode(this.top, s);
		}
		public SpanStack Clone()
		{
			return new SpanStack
			{
				top = this.top
			};
		}
		object ICloneable.Clone()
		{
			return this.Clone();
		}
		public SpanStack.Enumerator GetEnumerator()
		{
			return new SpanStack.Enumerator(new SpanStack.StackNode(this.top, null));
		}
		IEnumerator<Span> IEnumerable<Span>.GetEnumerator()
		{
			return this.GetEnumerator();
		}
		IEnumerator IEnumerable.GetEnumerator()
		{
			return this.GetEnumerator();
		}
	}
}
